/**
 * 
 */
package com.effectiv.gooruda.rest.api.service;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import org.hornetq.api.core.management.ObjectNameBuilder;
import org.hornetq.api.jms.management.JMSQueueControl;
import org.hornetq.api.jms.management.JMSServerControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Dhrubo
 * 
 */
//@Component
public class HornetQManagementHelper {

	@Autowired
	private MBeanServerConnection mBeanServerConnection;

	public JMSQueueControl getJMSQueueControl(String queueName) {
		JMSQueueControl queueControl = null;
		try {
			
			ObjectName on = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName);
			
			
			queueControl = MBeanServerInvocationHandler.newProxyInstance(
					mBeanServerConnection, on, JMSQueueControl.class, false);
		} catch (Exception e) {
			
			e.printStackTrace();
		}

		return queueControl;
	}

	public JMSServerControl getJMSServerControl() {
		ObjectName on;
		JMSServerControl serverControl = null;
		try {
			on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();
			serverControl = MBeanServerInvocationHandler.newProxyInstance(
					mBeanServerConnection, on, JMSServerControl.class, false);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return serverControl;
	}
}
